package com.hardy.leecode.model;

import com.hardy.basic.Array;
import lombok.ToString;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Author: Hardy
 * Date:   2020/6/27
 * Description:
 **/
public class ListNode {

    public int val;
    public ListNode next;

    public ListNode(int x) {
        val = x;
    }

    public ListNode(int x, ListNode next) {
        this.val = x;
        this.next = next;
    }

    public static ListNode gen(int[] a) {
        ListNode head = null;
        ListNode node = null;

        for (int i : a) {
            if (head == null) {
                head = new ListNode(i);
                node = head;
            } else {
                node.next = new ListNode(i);
                node = node.next;
            }
        }
        return head;
    }

    @Override
    public String toString() {
        ListNode node = this;
        StringBuilder sb = new StringBuilder();

        while (node != null) {
            sb.append(node.val).append(", ");
            node = node.next;
        }
        return sb.toString();
    }
}
